import sys
import glob
sys.path.append('gen-py')
sys.path.append('/home/vagrant/fbsource/build/fbthrift/thrift/lib/py/thrift_py.lib_install/thrift_py')

from DDM import UDPService
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer

class UDPHandler:
    def add(self, n1, n2):
        return n1 + n2

if __name__ == '__main__':
    handler = UDPHandler()
    processor = UDPService.Processor(handler)

    transport = TSocket.TServerSocket(port=9090)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

    # You could do one of these for a multithreaded server
    # server = TServer.TThreadedServer(
    #     processor, transport, tfactory, pfactory)
    # server = TServer.TThreadPoolServer(
    #     processor, transport, tfactory, pfactory)

    print('Starting the server...')
    server.serve()
    print('done.')